//
//  WOTableSection.m
//  WOPrototype
//
//  Created by Olof Millberg on 2010-04-26.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "WOTableSection.h"


@implementation WOTableSection
@synthesize title, rows;

+ (id) sectionWithTitle:(NSString*)aTitle rows:(WOTableRow *) firstRow, ...
{
	WOTableSection *section = [[[WOTableSection alloc] init] autorelease];
	
	section.title = aTitle;
	
	id eachRow;
	va_list argumentList;
	if (firstRow)                      // The first argument isn't part of the varargs list,
	{                                   // so we'll handle it separately.
		[section.rows addObject: firstRow];
		va_start(argumentList, firstRow);          // Start scanning for arguments after firstObject.
		while (eachRow = va_arg(argumentList, id)) // As many times as we can get an argument of type "id"
			[section.rows addObject: eachRow];               // that isn't nil, add it to self's contents.
		va_end(argumentList);
	}
	return section;
}

- (NSInteger) numberOfRows
{
	return [rows count];
}

- (NSString *) identifierAtRow:(NSInteger)row
{
	return ((WOTableRow*)[rows objectAtIndex:row]).identifier;
}

- (CGFloat) heightForRow:(NSInteger)row
{
	return ((WOTableRow*)[rows objectAtIndex:row]).height;
}

- (id) init
{
	if (self = [super init])
	{
		self.title = @"";
		self.rows = [NSMutableArray array];
	}
	
	return self;
}

- (void) dealloc
{
	[title release];
	[rows release];
	[super dealloc];
}

@end
